package com.diamond.web.model.system;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name="sys_user")
@JsonIgnoreProperties({"roles"})
public class User {
	@Id
	@GeneratedValue
    private Long id;

    @NotBlank(message="用户名不得为空")
    @Column(nullable=false,unique=true)
    private String username;

    @NotBlank(message="密码不得为空")
    @Column(nullable=false)
    private String password;

    private String state;

    private Date createTime = new Date();
    
    @ManyToMany
    @JoinTable(name="sys_user_role")
    private Set<Role> roles;

    public User(String username, String password) {
    	this.username=username;
    	this.password=password;
	}

	public User() {
	}

	public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state == null ? null : state.trim();
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
}